package org.example.hello5_routingKey_topic;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RoutingTopicConfig {

    /**
     * 声明交换机
     */
    @Bean
    public TopicExchange topicExchange() {
        TopicExchange topicExchange = new TopicExchange("topic_exchange");
        return topicExchange;
    }
    /**
     * 声明队列1
     */
    @Bean
    public Queue topicQueue1() {
        Queue queue = new Queue("topic_queue1");
        return queue;
    }

    /**
     * 声明队列2
     */
    @Bean
    public Queue topicQueue2() {
        Queue queue = new Queue("topic_queue2");
        return queue;
    }

    /**
     * 队列1绑定交换机
     */
    @Bean
    public Binding topicBinding1(){
        Binding binding= BindingBuilder.bind(topicQueue1()).to(topicExchange()).with("user.*");
        return binding;
    }


    /**
     * 队列2绑定交换机
     */
    @Bean
    public Binding topicBinding2(){
        Binding binding= BindingBuilder.bind(topicQueue2()).to(topicExchange()).with("user.#");
        return binding;
    }

}
